/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.event.MouseEvent;
import org.lwjgl.opengl.GL11;

public class Menu extends GUIComponent {

    GUILayout child;
    String title;

    public Menu(String title, GUILayout child) {

        this.title = title;
        this.child = child;

        child.setVisible(0);
        child.setIsSubMenu(1);
    }

    public void draw() {
        super.draw();


        GL11.glColor4f(parent.TEXT[0], parent.TEXT[1], parent.TEXT[2], parent.TEXT[3]);
        parent.font.drawString(locX + 5, locY, title, 1, 1);
        child.draw();
    }

    public int mousePressed(int mouseX, int mouseY) {

        //check if mouse pressed on this object
        if (mouseX > locX && mouseX < locX + cWidth) {
            if (mouseY > locY && mouseY < locY + cHeight) {
                parent.focusedComp = this;
                showChild();
                child.open = 1;
                return 1;
            }

        }
            return child.mousePressed(mouseX,mouseY);
        
    }

    public int mouseMoved(int mouseX, int mouseY) {

        int overMe = super.mouseMoved(mouseX, mouseY);
        int overChild = child.mouseMoved(mouseX, mouseY);



        if (overMe == 1 || overChild == 1) {
            showChild();
            return 1;
        } else {
            child.setVisible(0);
            child.open = 0;
            return 0;
        }


    }

    private void showChild() {
        child.setVisible(1);
        child.setPosition(locX + cWidth-10, locY + cHeight + 1);
        child.open = 1;
        child.doLayout();


    }
}
